<?php
   $mtime = microtime();
   $mtime = explode(" ",$mtime);
   $mtime = $mtime[1] + $mtime[0];
   $starttime = $mtime;

	
  
//Magic!

require('../Magic/magic.php');
$userSys = new UserSystem();



///echo $userSys->makeNewUser('test','pass','pass','test@test.com','114/12/2922');
//die();

//System,
if(isset($_GET['profile'])){
$profile = $_GET['profile'];
}else{$profile=1;}
//get current user vars

$uid		= $userSys->getAttribute('uid');
$username	= $userSys->getAttribute('name');




/*
$n = new User;

$n->set('name','simon');
$n->setPassword('pass');
$n->set('registered',time());
$n->setPermissions('2');
$n->set('email','MAIL');
$n->set('avatar','avtar');

$n->write();
*/
?>

<style>
a {
color:#ffffff;
}
</style>
<div style='background-color:black;padding:10px;margin:0;color:#ffffff;font-weight:bold;'>
<?php
//$userSys->login('bag','pass');
if($userSys->authenticated()){
	echo "Welcome back <a href='index.php?profile=".$uid."'>".$username.'</a> - <a href="edit.php?profile='.$uid.'">Edit profile</a> - <a href="log.php?log=out">logout</a>';
}else{
	echo "<form action='log.php' method='post'><input name='name' type='text'><input name='pass' type='password'><input type='submit' value='Send'></form>";
}

?>
</div>

<div style='float:right;padding:5px;margin:15px;background-color:black;color:white;width:200px;'>
<strong>Users List</strong> <br>
<?php

	$userslist = $userSys->getUserList();
	foreach($userslist as $usr){
		echo "<a href='?profile={$usr['uid']}'>{$usr['name']}</a><br>";
	}
?>

</div>
<div style='padding:20px;'>
<b>Basic info:</b><br>
<?php

	$user = $userSys->getUserById($profile);
	
	if($user !==null){
		$profile = $user->getAsArray();
		foreach($profile as $att => $val){
			echo $att.' : '.$val.' <br>';
		}
		

		
	
	}else{
		echo 'invalid profile';
	}
	

?>



</div>

<?php
   $mtime = microtime();
   $mtime = explode(" ",$mtime);
   $mtime = $mtime[1] + $mtime[0];
   $endtime = $mtime;
   $totaltime = ($endtime - $starttime);
   echo "This page was created in ".$totaltime." seconds";
;?>
